@import "~scss/variables";
@import "~scss/mixins";

.sw-data-grid {
    overflow: hidden;
    background-color: $color-white;

    &.sw-data-grid--full-page {
        width: 100%;
        height: 100%;
        position: absolute;
        display: grid;
        grid-template-rows: 1fr auto;
    }

    .sw-data-grid__wrapper {
        -webkit-overflow-scrolling: touch;
        overflow-x: auto;
        overflow-y: auto;
    }

    .sw-data-grid__table {
        border-collapse: collapse;
        width: 100%;
    }

    .sw-data-grid__cell {
        padding: 0;
        margin: 0;
        font-size: $font-size-xs;
        color: $color-darkgray-200;
        border-right: 1px solid $color-gray-300;
        overflow: hidden;
        background-color: $color-white;

        &:last-child {
            border-right: 0 none;
        }
    }

    &.sw-data-grid--actions .sw-data-grid__cell {
        border-right: 1px solid $color-gray-300;

        &:last-child,
        &:nth-last-child(2) {
            border-right: 0 none;
        }
    }

    .sw-data-grid__cell-content {
        @include truncate;

        min-width: 0;
        padding: 20px;
        line-height: 22px;
        height: 64px;
        font-size: $font-size-xs;
        display: flex;
        align-items: center;

        .sw-field,
        .sw-field.sw-field--small {
            margin-bottom: 0;

            &:not(:last-child) {
                margin-right: 8px;
            }
        }

        .sw-field.sw-field--checkbox,
        .sw-field.sw-field--radio,
        .sw-field--checkbox,
        .mt-field--checkbox,
        .mt-switch,
        .sw-field--radio {
            display: block;
            margin-bottom: 0;
            width: auto;
        }

        .sw-label {
            margin-bottom: 0;
        }

        .sw-select {
            flex-shrink: 0;
            width: 100%;
        }

        a {
            color: $color-darkgray-200;
            text-decoration: none;

            &:hover {
                text-decoration: underline;
            }
        }

        .mt-icon,
        .sw-color-badge {
            flex-shrink: 0;
        }

        .sw-data-grid__inline-edit-cancel {
            line-height: 1;

            .mt-icon {
                width: 16px;
                height: 16px;
                padding: 4px;
            }
        }

        .sw-data-grid__inline-edit-save {
            line-height: 1;

            .mt-icon {
                width: 16px;
                height: 16px;
                padding-top: 5px;
                padding-right: 4px;
                padding-bottom: 5px;
                padding-left: 4px;
            }
        }
    }

    .sw-data-grid__cell-value {
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .sw-data-grid__cell--align-right {
        .sw-data-grid__cell-content {
            justify-content: flex-end;
        }

        .sw-data-grid-inline-edit {
            justify-content: flex-end;
        }
    }

    .sw-data-grid__cell--align-right.sw-data-grid__cell--header {
        .sw-data-grid__cell-content {
            flex-flow: row-reverse;
            justify-content: flex-start;
        }
    }

    .sw-data-grid__cell--align-left {
        .sw-data-grid__cell-content {
            justify-content: flex-start;
        }

        .sw-data-grid-inline-edit {
            justify-content: flex-start;
        }
    }

    .sw-data-grid__cell--align-center,
    .sw-data-grid__cell--icon-label {
        .sw-data-grid__cell-content {
            justify-content: center;
        }

        .sw-data-grid-inline-edit {
            justify-content: center;
        }
    }

    .sw-data-grid__cell-resize {
        position: absolute;
        top: 0;
        right: 0;
        bottom: 0;
        width: 0;
        height: 100%;
        background-color: $color-gray-300;
        cursor: ew-resize;
        opacity: 0;
        transition: all 0.2s ease-in-out;

        &.is--column-resizing {
            background-color: darken($color-gray-300, 10%);
        }
    }

    .sw-data-grid__action-edit-column {
        margin-left: 5px;

        .mt-icon {
            color: $color-gray-300;
        }
    }

    .sw-data-grid__header {
        &:hover {
            .sw-data-grid__cell-resize {
                opacity: 1;
                width: 4px;
            }
        }
    }

    .sw-data-grid__cell--header {
        position: sticky;
        top: 0;
        background-clip: padding-box;
        box-shadow: inset 0 -1px 0 $color-gray-300;
        background-color: $color-white;
        z-index: 6;
        overflow: visible;

        &.sw-data-grid__cell--selection {
            z-index: 7;
            box-shadow: inset -1px -1px 0 0 $color-gray-300;
        }

        .sw-data-grid__cell-content {
            position: relative;
            overflow: hidden;
        }
    }

    .sw-data-grid__cell--sortable:hover {
        cursor: pointer;
        background-color: $color-gray-100;
    }

    .sw-data-grid__cell--property {
        .sw-data-grid__sort-indicator {
            margin-left: auto;

            .mt-icon {
                padding: 4px;
            }
        }

        &.is--column-resizing {
            background-color: $color-shopware-brand-50;
        }

        &:hover {
            .sw-data-grid__action-edit-column .mt-icon {
                color: $color-darkgray-200;
            }
        }
    }

    &.is--resizing .sw-data-grid__cell--property {
        cursor: ew-resize;
        user-select: none;
    }

    .sw-data-grid__cell--selection {
        position: sticky;
        left: 0;
        width: 88px;
        min-width: 88px;
        max-width: 88px;
        border-right: 0;
        box-shadow: inset -1px 0 0 $color-gray-300;
        overflow: visible;
        z-index: 5;

        &.sw-data-grid__cell:nth-child(1) {
            border-right: 0;
        }

        .sw-field--checkbox {
            margin-bottom: 0;
        }

        .sw-data-grid__cell-content {
            justify-content: center;
        }
    }

    .sw-data-grid__bulk {
        position: absolute;
        white-space: nowrap;
        overflow: hidden;
        color: $color-darkgray-200;
        background: $color-white;
        font-size: $font-size-xs;
        left: 0;
        right: 0;
        height: 64px;
        z-index: 7;
        border-bottom: 1px inset $color-gray-300;
        padding: 20px 12px 20px 100px;
    }

    &.sw-data-grid--actions {
        .sw-data-grid__bulk {
            right: 88px;
        }
    }

    .sw-data-grid__bulk-selected {
        margin: 12px;

        &.sw-data-grid__bulk-selected-label {
            font-weight: bold;
        }

        &.sw-data-grid__bulk-selected-count {
            text-align: right;
        }

        &.sw-data-grid__bulk-max-selection {
            color: $color-crimson-500;
        }
    }

    .sw-data-grid__body .sw-data-grid__row {
        &:nth-child(even) .sw-data-grid__cell {
            background-color: $color-gray-100;
        }

        &:hover .sw-data-grid__cell {
            background-color: $color-shopware-brand-50;

            a {
                color: $color-shopware-brand-500;
            }
        }

        &.is--inline-edit {
            .sw-data-grid__cell {
                background-color: $color-shopware-brand-50;
                border-top: 1px solid $color-shopware-brand-500;
                border-bottom: 1px solid $color-shopware-brand-500;
            }

            .sw-data-grid__cell-content {
                padding: 10px;
                color: darken($color-gray-300, 10%);

                .mt-field {
                    margin-bottom: 0;
                }
            }

            .sw-data-grid__cell-value {
                display: inline-block;
                margin: 0 10px;
                color: darken($color-gray-300, 10%);
                user-select: none;
                cursor: default;
            }
        }

        &.is--selected {
            .sw-data-grid__cell {
                background-color: $color-shopware-brand-50;
            }
        }
    }

    .sw-data-grid__cell--actions {
        position: sticky;
        right: 0;
        width: 88px;
        min-width: 88px;
        max-width: 88px;
        box-shadow: inset 1px 0 0 $color-gray-300;
        overflow: visible;
        z-index: 4;

        &.is--loading {
            position: initial;
        }

        .sw-data-grid__cell-content {
            justify-content: center;
        }

        .mt-button + .mt-button {
            margin-left: 5px;
        }
    }

    .bulk-link .link {
        display: inline-block;
        position: relative;
        margin: 0;
        line-height: $line-height-xs;
        padding: 4px 12px;
        text-decoration: none;
        color: $color-darkgray-200;
        cursor: pointer;

        &:hover {
            text-decoration: underline;
        }

        &.link-danger {
            color: $color-crimson-500;
        }

        &.link-warning {
            color: $color-pumpkin-spice-500;
        }

        &.link-primary {
            color: $color-shopware-brand-500;
        }
    }

    .sw-media-preview-v2,
    .sw-media-preview {
        position: relative;
        width: 48px;
        height: 48px;
        border: 1px solid $color-gray-300;
        border-radius: $border-radius-default;
        background-color: $color-white;
        margin-right: 15px;
        flex-shrink: 0;

        .sw-media-preview-v2__item,
        .sw-media-preview__item {
            max-width: calc(100% - 5px);
            max-height: calc(100% - 5px);

            &.mt-icon {
                width: 100%;
                height: 100%;
            }
        }
    }

    .sw-avatar {
        margin-right: 15px;
        flex-shrink: 0;
    }

    .sw-data-grid__cell-settings {
        box-shadow: inset 1px -1px 0 $color-gray-300;
        z-index: 7;
    }

    &.is--scroll-x {
        .sw-data-grid__cell--actions::before {
            pointer-events: none;
            width: 8px;
            display: block;
            content: "";
            background: linear-gradient(to right, transparent, rgba(0, 0, 0, 10%));
            position: absolute;
            top: 0;
            bottom: 0;
            left: -8px;
        }

        .sw-data-grid__cell--selection::before {
            pointer-events: none;
            width: 8px;
            display: block;
            content: "";
            background: linear-gradient(to left, transparent, rgba(0, 0, 0, 10%));
            position: absolute;
            top: 0;
            bottom: 0;
            right: -8px;
        }

        &.sw-data-grid__cell--header::before {
            background: none;
            border-right: none;
            box-shadow: none;
        }

        .sw-data-grid__cell--selection {
            border-right: 0;
        }
    }

    &.is--compact {
        .sw-data-grid__body .sw-data-grid__cell-content {
            padding: 10px 20px;
            height: 42px;
        }

        .sw-media-preview-v2 {
            width: 32px;
            height: 32px;
        }

        .is--inline-edit .sw-data-grid__cell-content {
            .mt-block-field__block {
                min-height: var(--scale-size-32);
            }
        }
    }

    .sw-data-grid__body .sw-data-grid__cell--multi-line {
        .sw-data-grid__cell-content {
            display: block;
            height: auto;
            white-space: normal;
        }
    }

    .sort-indicator-enter-active,
    .sort-indicator-leave-active {
        transition: all 0.1s ease-in-out;
        transform: translateY(0);
        opacity: 1;
    }

    .sort-indicator-enter,
    .sort-indicator-leave-to {
        transform: translateY(10px);
        opacity: 0;
    }

    &__cell {
        .mt-number-field {
            margin-bottom: 0;

            &--size-small {
                height: 25px;
            }

            &__controls {
                display: none;
            }
        }
    }
}

.sw-data-grid.sw-data-grid--plain-appearance {
    .sw-data-grid__body {
        .sw-data-grid__row {
            &:nth-child(even) .sw-data-grid__cell {
                background-color: $color-white;
            }

            &:hover .sw-data-grid__cell {
                background-color: $color-shopware-brand-50;
            }

            &.is--inline-edit .sw-data-grid__cell,
            &.is--selected .sw-data-grid__cell {
                background-color: $color-shopware-brand-50;
            }

            &:last-child {
                .sw-data-grid__cell {
                    border-bottom: 0 none;
                }
            }
        }

        .sw-data-grid__cell--actions,
        .sw-data-grid__cell--selection {
            box-shadow: none;
        }

        .sw-data-grid__cell {
            border-right: 0 none;
            border-bottom: 1px solid $color-gray-300;
        }
    }

    .sw-data-grid__cell--header {
        border-right: 0 none;
    }

    .sw-data-grid__cell--header.sw-data-grid__cell--selection {
        box-shadow: inset 0 -1px 0 0 $color-gray-300;
    }

    .sw-data-grid__cell-settings {
        box-shadow: inset 0 -1px 0 $color-gray-300;
    }
}
